import { getAction, postAction, putAction } from '@/api/manage'

export default {
  async selectColumn(api) {
    let obj = {
      api,
    }
    var returnObj = {}
    const res = await getAction('/fieldshowsetting/xghAccountBookFieldShowSetting/getByApiAndAccountBookId', obj)
    if (res.code == 200) {
      if (res.result) {
        returnObj = {
          code: 200,
          updateId: res.result.id,
          columnData: JSON.parse(res.result.fieldSetting),
        }
      } else {
        returnObj = {
          code: 500,
        }
      }
      return returnObj
    } else {
      return (returnObj = {
        code: 404,
      })
    }
  },
  async addColumn(api, titleJson) {
    let obj = {
      api,
      fieldSetting: JSON.stringify(titleJson),
    }
    const res = await postAction('/fieldshowsetting/xghAccountBookFieldShowSetting/add', obj)
    if (res.code == 200) {
      return res.result
    }
  },

  async editColumn(api, titleJson, columnId) {
    let obj = {
      api,
      id: columnId,
      fieldSetting: JSON.stringify(titleJson),
    }
    const res = await putAction('/fieldshowsetting/xghAccountBookFieldShowSetting/edit', obj)
    return res
  },
}

